package cn.ekuma.epos.panel;

import java.util.List;

import com.openbravo.bean.I_AppUser;
import org.ofsm.IEvent;

import com.openbravo.bean.AppUser;
import com.openbravo.data.basic.BasicException;
import cn.ekuma.data.ui.swing.AbstractDTOTableModel;
import cn.ekuma.epos.businesslogic.RoleUtil;
import cn.ekuma.epos.datalogic.I_DataLogicSystem;


public   class JStateObjectChildDAOEditorPanel<K> extends AbstractJStateObjectChildDAOEditorPanel<K> {
   
  
    I_DataLogicSystem dlSystem;
	AppUser appUser;

    public JStateObjectChildDAOEditorPanel(AbstractDTOTableModel tableModel,AppUser user,I_DataLogicSystem dlSystem,String stateProcessName) {
    	super(tableModel,getUser(user),stateProcessName);
        this.dlSystem=dlSystem;
		AppUser appUser=user;
    }

    private static I_AppUser getUser(AppUser user){
    	return new I_AppUser() {
			@Override
			public String getName() {
				return user.getName();
			}

			@Override
			public String getId() {
				return user.getId();
			}
		};
	}

	@Override
	public void init() throws BasicException {
		if (stateProcessName == null || stateProcessName.isEmpty()) {
        } else {
            byte[] bf = dlSystem.getResourceAsBinary(stateProcessName);
            initStateMachine(bf);
        }
	}

	@Override
	List<IEvent> getUserStateProcessEvents() {
		return  RoleUtil.filterUserStateProcessEvents(appUser, stateProcessName, stateMachine.getTransitionEventByCurrentState());
	}
}

